package com.dong.demo;

public class Missle {
    private Point position;
    private Double speed;
    private Flyer target;//导弹的追赶目标

    public Missle(Point position, Double speed, Flyer target) {
        this.position = position;
        this.speed = speed;
        this.target = target;
    }
    public void catchFlyer(){
        if (position.getDis(target.getPosition())<1){
            System.out.println("追赶成功");
            Application.isStop=true;
            return;
        }
        //计算导弹0.05的位置变化量
        double vy=position.getSin(target.getPosition())*0.05*speed;
        double vx=position.getCos(target.getPosition())*0.05*speed;
        position.moveXY(vx,vy);
    }

    public Point getPosition() {
        return position;
    }
}
